package com.rabbit.eap.framework.utils;

import org.springframework.lang.Nullable;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.framework.utils
 * @className HttpKit
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/4/19 20:00
 * <p>Description: HttpKit
 *
 * </p>

 */
public class HttpKit {
    /**
     * 获取 HttpServletRequest
     */
    @Nullable
    public static HttpServletResponse getResponse() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            return requestAttributes.getResponse();
        }
        return null;
    }
    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        }
        return null;

    }
}
